{extend name="index:layout" /}

{block name="menu"}{/block}

{block name="content"}

{php}
$types[intval($rsdb['type'])]="checked='checked'";
$rsdb['answer1']=$rsdb['type']?"":$rsdb['answer'];
if($rsdb['type']){
	$displays[0]="style='display:none;'";
}else{
	$displays[1]="style='display:none;'";
}
{/php}

<SCRIPT LANGUAGE="JavaScript">
<!--
function upfile(url,par,name,size){
	document.getElementById(par).value=url;
}
function SelectType(i){
	$('#selecttype0').hide();
	$('#selecttype1').hide();
	$('#selecttype'+i).show();
}
function addType(){	
	var list1=$('.ListType').children().length;
	var ListType1='<div class="list"><div><span>标题</span> <input name="answers['+list1+'][title]" type="text" size="50"/></div><div><span>描述</span> <textarea name="answers['+list1+'][desc]" cols="50" rows="3"></textarea></div><div><span>图片</span> <input name="answers['+list1+'][pic]" type="text" id="out_url'+list1+'" placeholder="请上传图片" size="50"/><em><iframe frameborder=0  scrolling=no src="{:iurl("index/upfile/index")}?fn=upfile&par=out_url'+list1+'"></iframe></em></div><div><span>链接</span> <input name="answers['+list1+'][link]" type="text" size="50"/> (必填项)</div></div>';
	$(".ListType").append(ListType1);
	hide_desc();
}
function hide_desc(){
	$('.ListType .list').each(function(){
		$(this).children().eq(1).hide();
	});
}
//-->
</SCRIPT>
<style>
.ListType .list{border:#DDD solid 1px;margin:2px auto 3px auto;background:#EFEFEF;}
.ListType .list div{border-top:#DDD solid 1px;padding:5px 5px 5px 50px;position:relative;}
.ListType .list div span{display:block;width:45px;height:30px;line-height:30px;text-align:right;position:absolute;top:0;left:0;}
.ListType .list div input{width:200px;border:#DDD solid 1px;height:20px;}
.ListType .list div textarea{border:#DDD solid 1px;height:100px;width:90%;} 
.ListType .list div em{display:block;width:300px;height:28px;position:absolute;left:260px;top:3px;overflow:hidden;}
</style>
<form method="post" action="{:purl('edit','id='.$id)}">
<div class="MainContainers">
  <div class="Header"><span class="tag">添加关键字</span><span class="more">&gt;&gt;</span></div>
  <table class="FormTable">
    <tr>
      <td class="tdL">关键词：</td>
      <td class="tdR"><input name="ask" type="text" style="width:200px;border:#DDD solid 1px;height:20px;" value="{$rsdb['ask']}"/>（多个个关键词，请用半角空格隔开）</td>
    </tr>
    <tr>
      <td class="tdL">内容类型：</td>
      <td class="tdR"><input name="type" type="radio" value="1" onClick="SelectType(1)" {$types[1]} />
        图文
        <input name="type" type="radio" onClick="SelectType(0)" value="0" {$types[0]} />
        纯文本 </td>
    </tr>
    <tr id='selecttype0' {$displays[0]}>
      <td class="tdL">回复内容：</td>
      <td class="tdR"><textarea name="answer" style="border:#DDD solid 1px;height:100px;width:90%;">{$rsdb['answer1']}</textarea></td>
    </tr>
    </tr>
    
    <tr id='selecttype1' {$displays[1]}>
      <td  class="tdL">回复内容：<i title="添加多一项" class="fa fa-plus-circle" style="color:blue;font-size:18px;" onClick="addType()"></i></td>
      <td class="tdR"><div class="ListType">
{php}
$answers= unserialize($rsdb['answer']);
$i=0;
foreach($answers AS $key=>$rs){
{/php}
          <div class="list">
            <div><span>标题</span>
              <input name="answers[{$i}][title]" value="{$rs['title']}" type="text"/>
            </div>
            <div><span>描述</span>
              <textarea name="answers[{$i}][desc]">{$rs['desc']}</textarea>
            </div>
            <div> <span>图片</span>
              <input name="answers[{$i}][pic]" type="text" value="{$rs['pic']}" id='out_url{$i}' placeholder="请上传图片"/>
              <em>
              <iframe frameborder=0  scrolling=no src="{:iurl('index/upfile/index')}?fn=upfile&par=out_url{$i}"></iframe>
              </em> </div>
            <div><span>链接</span>
              <input name="answers[{$i}][link]" type="text" value="{$rs['link']}"/>
              (必填项)</div>
          </div>
{php}
$i++;
}if($i<1){
{/php}
          <div class="list">
            <div><span>标题</span>
              <input name="answers[0][title]" type="text"/>
            </div>
            <div><span>描述</span>
              <textarea name="answers[0][desc]"></textarea>
            </div>
            <div> <span>图片</span>
              <input name="answers[0][pic]" type="text" id='out_url0' placeholder="请上传图片"/>
              <em>
              <iframe frameborder=0  scrolling=no src="{$webdb['www_url']}/do/upfile.php?fn=upfile&dir=weixinautoreply&label=out_url0"></iframe>
              </em> </div>
            <div><span>链接</span>
              <input name="answers[0][link]" type="text"/>
              (必填项)</div>
          </div>
{php}
}if($i>1){
{/php}

<SCRIPT LANGUAGE="JavaScript">
hide_desc();
</SCRIPT>
{php}
EOT;
}
{/php}
        </div></td>
    </tr>
    <tr>
      <td class="tdL">排序值：</td>
      <td class="tdR"><input name="list" type="text" value="{$rsdb['list']}" style="width:30px;border:#DDD solid 1px;height:20px;"/></td>
    </tr>
  </table>
  <input name="id" type="hidden" id="id" value="{$id}" />
  <div class="submits"><input type="submit" name="Submit2" value="提 交" /></div>
  </div>
</div>
</form>
{/block}